package site.jlopen.assets.shiro.match;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.springframework.stereotype.Component;

import site.jlopen.assets.shiro.token.JwtToken;

@Component
public class CredentialsMatch extends HashedCredentialsMatcher {

	public CredentialsMatch() {
		super();
	}

	public CredentialsMatch(String hashAlgorithmName) {
		super(hashAlgorithmName);
	}
	
	@Override
	public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
		// 如果免密登录则直接返回true
		if(token instanceof JwtToken) {
			return true;
		}
		this.setHashAlgorithmName("md5");
	    //此处配置修改需注意,会导致密码验证失败
		this.setHashIterations(1024);
		this.setStoredCredentialsHexEncoded(true);
		// 否则按照之前验证密码
		return super.doCredentialsMatch(token, info);
	}
	
}
